home *** CD-ROM | disk | FTP | other *** search
- /* _WRITE.C --- p. 677 */
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- char buffer[80] = "Testing _write ...........";
- main()
- {
- char fname[40], *p_fname;
- int filehandle, bytes;
- printf("Enter name of an existing file: ");
- p_fname = gets(fname);
- /* Open the file using _open */
- if((filehandle = _open(p_fname, O_RDWR)) == -1)
- {
- printf("Error opening file: %s\n", fname);
- exit(0);
- }
- printf("File %s opened.\n", fname);
- /* Now write out buffer */
- if((bytes = _write(filehandle, buffer, 80)) != -1)
- printf("%d bytes written\n", bytes);
- /* Now close the file */
- if(_close(filehandle) != 0)
- {
- printf("Error closing file with _close\n");
- exit(0);
- }
- printf("File %s closed.\n", fname);
- }